package com.sakura.factory.simplefactory.pizzastore.order;

import com.sakura.factory.simplefactory.pizzastore.pizza.CheesePizza;
import com.sakura.factory.simplefactory.pizzastore.pizza.GreekPizza;
import com.sakura.factory.simplefactory.pizzastore.pizza.PepperPizza;
import com.sakura.factory.simplefactory.pizzastore.pizza.Pizza;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * @Author Sakura
 * @Date 2022/11/10 11:56
 * @Version 1.0
 */
public class OrderPizza {
    // 构造器

    /**
     * TODO 违反了开闭原则,每次新增都要修改客户端;
     *          1.优点是比较好理解，简单易操作。
     *          2.缺点是违反了设计模式的ocp原则，即对扩展开放，对修改关闭。即当我们给类增
     *            加新功能的时候，尽量不修改代码，或者尽可能少修改代码
     */
    public OrderPizza() {
        Pizza pizza = null;
        String orderType; // 订购披萨的类型
        do {
            orderType = getType();
            if (orderType.equals("greek")) {
                pizza = new GreekPizza();
                pizza.setName(" 希腊披萨 ");
            } else if (orderType.equals("cheese")) {
                pizza = new CheesePizza();
                pizza.setName(" 奶酪披萨 ");
            } else if (orderType.equals("pepper")) {
                pizza = new PepperPizza();
                pizza.setName("胡椒披萨");
            } else {
                break;
            }
            //输出pizza 制作过程
            pizza.prepare();
            pizza.bake();
            pizza.cut();
            pizza.box();

        } while (true);
    }


    // 写一个方法，可以获取客户希望订购的披萨种类
    private String getType() {
        try {
            BufferedReader strin = new BufferedReader(new InputStreamReader(System.in));
            System.out.println("input pizza 种类:");
            String str = strin.readLine();
            return str;
        } catch (IOException e) {
            e.printStackTrace();
            return "";
        }
    }
}
